package com.atguigu.binarysearch;

/**
 * @author xgc
 * @create 2021-07-22 11:06
 * 内部枚举类实现（防止反射攻击）
 */
public class SingletonFactory {
    //内部枚举类
    private enum EnumSingleton{
        Singleton;
        private Singleton6 singleton;

        //枚举类的构造方法在类加载是被实例化
        private EnumSingleton(){
            singleton = new Singleton6();
        }
        public Singleton6 getInstance(){
            return singleton;
        }

    }
    public static Singleton6 getInstance(){
        return EnumSingleton.Singleton.getInstance();
    }
}

class Singleton6{
    public Singleton6(){};
}
